//
//  HLIMInputAtCache.m
//  YueYue
//
//  Created by hulu001 on 2024/1/12.
//

#import "HLIMInputAtCache.h"

@interface HLIMInputAtCache ()

@property (nonatomic,strong) NSMutableArray *items;

@end

@implementation HLIMInputAtCache


- (instancetype)init
{
    self = [super init];
    if (self) {
        _items = [[NSMutableArray alloc] init];
    }
    return self;
}

- (NSArray<HLIMInputAtObject *> *)allAtObject
{
    return self.items;
}

- (void)clean
{
    [self.items removeAllObjects];
}

- (void)addItem:(HLIMInputAtObject *)item
{
    [self.items addObject:item];
}

- (HLIMInputAtObject *)item:(NSString *)name
{
    __block HLIMInputAtObject *item;
    [_items enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        HLIMInputAtObject *object = obj;
        if ([object.nick isEqualToString:name])
        {
            item = object;
            *stop = YES;
        }
    }];
    return item;
}

- (void)removeName:(NSString *)name
{
    __block HLIMInputAtObject *item;
    [_items enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        HLIMInputAtObject *object = obj;
        if ([object.nick isEqualToString:name]) {
            item = object;
            *stop = YES;
        }
    }];
    if (item) {
        [_items removeObject:item];
    }
}


@end
